import {
    createRouter,
    createWebHashHistory
} from "vue-router";
import content from '../components/content.vue'
import exports from "../components/exports.vue"
import Home from "../components/Home.vue";
import post from "../components/post.vue"
import questions from "../components/questions.vue"
const _isMobile = function () {
    const flag = navigator.userAgent.match(
        /(phone|pad|pod|iPhone|iPod|ios|iPad|Android|Mobile|BlackBerry|IEMobile|MQQBrowser|JUC|Fennec|wOSBrowser|BrowserNG|WebOS|Symbian|Windows Phone)/i
    )
    return flag
}
const routes = [{
        path: "/",
        redirect: "/home"

    },
    {
        path: "/exports",
        name: "exports",
        component: exports,
    },
    {
        path: "/questions",
        name: "questions",
        component: questions,
    },
    {
        path: "/content",
        name: "content",
        component: content,
    },
    {
        path: "/post",
        name: "post",
        component: post,
    },
    {
        path: '/home',
        name: "home",
        component: Home,
        meta: {
            title: "首页",
        },
    },

]
const router = createRouter({
    history: createWebHashHistory(),
    routes,
    scrollBehavior(to, from, savedPosition) {
        if (savedPosition || to) {
            // 如果之前有保存滚动位置，则直接滚动到该位置
            return savedPosition;
        } else {
            否则滚动到页面顶部
            return {
                top: 0
            };
        }
    },
})
export default router;